Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

String to int and int to String

$
0
0
Hello everybody, I'm trying to write a very basic, simple code that will "talk" to you, based on your answers
The problem here is, when I'm trying to use if it gives me an error, I understand that is because variable is a String but how can I solve this?
Here's my code

First class
import java.util.Scanner;
public class ap {
	
	public static void main(String[] args){

	Scanner input = new Scanner(System.in);
	
	
	Tuna tunaObject = new Tuna();
	salmon salmon1Object = new salmon();
	
System.out.println("What is your name? ");
String name = input.nextLine();
tunaObject.simpleMessage(name);
String salmon1 = input.nextLine();
salmon1Object.Message(salmon1);





Second class
public class Tuna {
	public void simpleMessage(String name){
		System.out.println("Hello "  + name );
		System.out.println("How old are you?");


		}
}


and third class
public class salmon {
public void Message(String salmon){
if(salmon<0)
{
	System.out.println(salmon+ "? That is impossible");
	
}

}}


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>