Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
It says "incompatible types: String cannot be converted to char"
How to fix it?
Here is the example.
This is your solution :
public class NewMain {
public static void main(String args[]) throws ParseException {
Scanner s = new Scanner(System.in);
char yes;
do {
System.out.println("Hi");
yes = s.next().charAt(0);
} while (yes == 'Y'); // if u enter 'Y' the it will continue
}
}
To exit enter any thing other then 'Y'
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I am having problem to invoke Scanner class from second method in main method. My code is this:
import java.util.Scanner;
public class Main{
static void checkAge(int age){
Scanner new_age = new Scanner(System.in);
age = new_age.nextInt();
System.out.println("Enter your age");
if(age < 18){
System.out.println("You are a minor");
} else {
System.out.println("You are of apropriate age");
}
}
public static void main(String[] args){
checkAge();
}
}
I get an error:
Main.java:18: error: '.class' expected
checkAge(Scanner.new_age(int));
^ 1 error
Call you function with arguments : checkAge(18); or checkAge(15);as you checkAge() requires parameters to check the conditions.
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 2 years ago.
Improve this question
Here is the question:
Write a recursive void method that has one parameter which is an integer and that writes to the screen the number of asterisks “*” given by the argument. The output should be all in one line. Assume that the argument is positive.
It is not a homework or assignment. Just a question in the slides with no answers...
I just don't know how to do it. I am a noob in this
here is my code and what i know
import java.util.Scanner;
public class Ez {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String str = input.nextLine();
String words[] = str.split("\\s");
int length = words.length;
int clength = str.length();
System.out.println(length);
System.out.println(clength);
}
public static void asterisksCounter (int n) {
}
}
Any big brains that know how to solve this question?
Thank you :)
While this is not a place to just ask a question and get an answer, since you mentioned that you have no idea how recursion works, giving you the code.
static void write(int n){
if(n == 0){
return;
}
System.out.print("*");
write(n-1);
}
General expectation is for the OP to try the problem by themselves, inform the community of the effort they put in and where exactly they are stuck. We would have been happier to help you after seeing some code from your side in the write() method.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
What I'm trying to do is progressively "reverse print" an alphabetical string from right to left like this:
A
BA
CBA
DCBA
etc...
Here is the foundation I'm working from which currently prints in normal order:
public static void main(String[] args)
{
String output = "";
for(char alphabet = 'A'; alphabet <='Z'; alphabet++ )
{
output += alphabet;
System.out.println(output);
}
}
Any help at all would be appreciated.
Change output += alphabet; tooutput = alphabet + output;
This does the job.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
I am trying to calculate the factorial of the integer user inputs, but it does not return anything. Why?
Thanks.
import java.util.Scanner;
`class App {
public static int factorial(int n) {
if (n == 0) {
return 1;
} else {
int recurse = factorial(n - 1);
int result = n * recurse;
return result;
}
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter an integer to calculate its factorial: ");
int users = input.nextInt();
factorial(users);
}
}
The problem in your code is that you are have not giving a print statement for displaying factorial of the number entered. Just returning a value will not print it. If you are working in BlueJ environment, you can only use the code by directly executing the method factorial. Thank You.
The problem in your code is that , you are have not given a print statement for >displaying factorial of the number entered.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm having a trouble figuring out how to solve this issue when it just stops when I call this method when I input letters and other types. What is the problem with my code? Can anyone help? Thanks in advance!
Here is my code:
public int selectOption(int maxRange, String sourceType) throws IOException
{
do
{
try
{
userInput = input.nextInt();
}//end try
catch(Exception e)
{
validInput=false;
input.next();
}//end catch
if (userInput<1 || userInput>maxRange)
{
MovieHouse.clearScreen();
System.out.println("Select from the options only!");
loadHeader();
if(sourceType.equals("main"))
MovieHouse.homeMenu();
else if(sourceType.equals("movie menu"))
loadMovieMenu();
}//end if
}while(userInput<1 || userInput>maxRange || validInput==false);
return userInput;
}//end selectOption
"input letters" - Does it mean normally the program take digits and you are providing char as input.
Not clear what is your issue.