Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
import java.util.*;
public class Ex13 {
static Scanner in = new Scanner(System.in);
public static void main(String[] args) {
char firstL,secondL;
System.out.println("insert first l");
firstL=in.next().charAt(0);
System.out.println("insert second l");
secondL=in.next().charAt(0);
if (){
System.out.println("kk");
}
}
}
I need firstL and secondL to equal in the if section but I can't because the firstL and the secondL is a char type and I need to transform it to a Unicode so I can finish the project
Why don't you just check the value?
char firstL,secondL;
System.out.println("insert first l");
firstL=in.next().charAt(0);
System.out.println("insert second l");
secondL=in.next().charAt(0);
if (firstL == secondL){
System.out.println("kk");
}
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
Code I wrote is below -
public class Demo{
public static void main(String[] args){
System.out.print(“Hearing in the distance”);
System.out.print(“Two mandolins like creatures in the “);
System.out.print(“dark”);
System.out.print(“Creating the agony of ecstacy.”);
System.out.println(“ - George Barker”);
}
}
I want to show each print one by one after each enter button pressed.
`
use java.util.Scanner
if you call Scanner.nextLine() your app waits until you write something and press enter or you can press enter without writing anything.
You can do like this below - after every enter button press it will print next value of course you can edit the code accordingly
private static void printNext(){
Scanner scanner = new Scanner(System.in);
int count = 3;
while(count> 0) {
if(count == 1){
System.out.println("Hearing in the distance");
}else if(count ==2 ){
System.out.println("Two mandolins like creatures in the");
}else {
System.out.println("Creating the agony of ecstacy.");
}
count--;
if (scanner.hasNextLine()) {
scanner.nextLine();
}
}
}
Hope this will help you.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I want to get a user input number to print out "Color 1 Color 2..." etc. depending on what number the input is.
I want to do this but in java, and I'm not quite sure where to find it.
How to iterate a for loop for a user input in Java?
That will do the work, using only standard java classes (java.io.Console):
import java.io.Console;
public class Consoler {
public static void main(String[] args) {
final Console console = System.console();
console.printf("How may times?\n");
final String line = console.readLine();
try {
final int quantity = Integer.parseInt(line);
for (int i = 1; i <= quantity; i++) {
System.out.printf("Color %d ",i);
}
System.out.println();
} catch (final NumberFormatException e) {
System.err.println(line + " is not a number.");
}
}
}
java.util.Scanner is probably what you're looking for. As for the for loop, you should google Java for loop and read up on how they work. Then combine the two concepts.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
import java.util.*;
class Sort {
public static void main(String..s) {
int a[]=new a[5];
Scanner sc=new Scanner(System.in);
System.out.println("Enter 5 Numbers");
for(int i=0;i<5;i++) {
a[i]=sc.nextInt();
}
for(int i=0;i<5;i++) {
System.out.println("Before Sorting"+ a[i]);
}
}
}
Please change
int a[]=new a[5];
to
int a[]=new int[5];
Also change String..s to String s[]
Please comment for further help.
Try these utility functions:
java.util.Arrays.sort(...): Sorts the specified array
java.util.Arrays.toString(...): Returns a nicely formatted string representation of the array. Don't forget to print it out :-)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
this is my code, when I enter 25000 the result being (25000=1,5000=1) while it must be only 25000=1, but if I enter 50,000 the result correct 50,000=2 but only for 25000 is wrong I don't know why it is
import java.util.Scanner;
class Mawa{
public static void main(String[]a){
int bestwpenj,da,penj,num;
Scanner input=new Scanner(System.in);
System.out.println("enter a number");
System.out.println();
num=input.nextInt();
bestwpenj=num/25000;
da=(num%25000)/10000;
penj=(num%10000)/5000;
System.out.println("25000= "+bestwpenj+"\n"+"10000= "+da+"\n"+"5000= "+penj);
}}
thanks for helping.
You mean like this?
import java.util.Scanner;
class Mawa{
public static void main(String[]a){
int bestwpenj,da,penj,num;
Scanner input=new Scanner(System.in);
System.out.println("enter a number");
System.out.println();
num=input.nextInt();
bestwpenj=num/25000;
da=(num%25000)/10000;
penj=(num%25000%10000)/5000;
System.out.println("25000= "+bestwpenj+"\n"+"10000= "+da+"\n"+"5000= "+penj);
}}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
import java.io.IOException;
import java.util.Scanner;
public class fflush{
public static void main(String [] args) throws IOException{
Scanner input=new Scanner(System.in);
int a;
System.out.print("Enter an integer:");
a = input.nextInt();
String b,c;
System.out.print("Enter a string:");
b = input.nextLine();
System.out.print("Enter another string:");
c = input.nextLine();
}
}
//result is//
Enter an integer:4
Enter a string:Enter a nother string:
You only "flush" the output in Java.
I suspect you mean, when to discard the rest of the line. To do this you can call
input.nextLine();
You need to do this after nextInt() as you expect to be reading from the next line.