Question
java

Create a conditional expression that evaluates to string negative if userVal is less than 0, and non-negative otherwise E
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Scanner;

public class NegativeOrPositive {

public static void main(String[] args) {
  
  
   Scanner scnr = new Scanner(System.in);
  
   System.out.print("User value is: ");
  
   //storing the user value in variable 'num'
   int num = scnr.nextInt();
  
   //conditional expression to find negative or non-negative number
   if(num < 0)
   {
     //printing string "negative"
     System.out.println(num+" is negative");
   }
   else
   {
     //printing the string "non-negative"
     System.out.println(num+" is non-negative");
   }
}
}

2:02 AM FILE EDIT X NegativeOrPositive.java import java.util.Scanner; 2 4 public class Negative0r Positive { public static vo2:03 AM NegativeOrPositive.java Stopped User value is: -9 -9 is negative O V2:03 AM NegativeOrPositive.java Stopped User value is: 15 15 is non-negative O V

Add a comment
Know the answer?
Add Answer to:
java Create a conditional expression that evaluates to string 'negative" if userVal is less than 0,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • can anyone solve this for me, python? Create a conditional expression that evaluates to string 'negative'...

    can anyone solve this for me, python? Create a conditional expression that evaluates to string 'negative' if user_val is less than 0, and non-negative otherwise. Sample output with input:-9 -9 is negative 1 user_val - int(input) 3 cond_str. 4 if user_val < 7 print(user_val, 'is', cond_str) Run

  • Java: Create the skeleton. Create a new file called ‘BasicJava4.java’ Create a class in the file...

    Java: Create the skeleton. Create a new file called ‘BasicJava4.java’ Create a class in the file with the appropriate name. public class BasicJava4 { Add four methods to the class that return a default value. public static boolean isAlphabetic(char aChar) public static int round(double num) public static boolean useSameChars(String str1, String str2) public static int reverse(int num) Implement the methods. public static boolean isAlphabetic(char aChar): Returns true if the argument is an alphabetic character, return false otherwise. Do NOT use...

  • The code below accepts and evaluates an integer expression with the following operators: +, _, *,...

    The code below accepts and evaluates an integer expression with the following operators: +, _, *, and /. Your task is to modify it to include the % remainder operator that has the same precedence as * and /. No need to rewrite the entire program, just insert the needed statements. import java.util.Stack; public class EvaluateExpression { public static void main(String[] args) {     // Check number of arguments passed     if (args.length != 1) {       System.out.println(         "Usage:...

  • using RECURSIVE Functions in Java, create a public static String doubleLetters (String word) For ex) that...

    using RECURSIVE Functions in Java, create a public static String doubleLetters (String word) For ex) that returns “one” as “oonnee”

  • JAVA ONLY I have a programming project, and I have to create a method called String...

    JAVA ONLY I have a programming project, and I have to create a method called String computePay(double hours) - computes the weekly pay for a Worker. Returns the output as a String that always displays the result to 2 decimal points. This is what I have done thus far... Can you help? public class Worker{ private String name; private double salaryrate; private double a;    public void Gavin(String uname, double usalaryrate){ name=uname; salaryrate=usalaryrate; }    public String computePay (double hours){...

  • With Java Language: In this assignment, you are to create a class named Payroll. In the...

    With Java Language: In this assignment, you are to create a class named Payroll. In the class, you are to have the following data members: name: String (5 pts) .İd: String (5 pts) hours: int (5 pts) rate: double (5 pts) private members (5 pts) You are to create no-arg and parameterized constructors and the appropriate setters(accessors) and getters (mutators). (20 pts) The class definition should also handle the following exceptions: An employee name should not be empty, otherwise an...

  • JAVA Overview Create a method public static void spongeBobify(String inputPath, String outputPath...

    JAVA Overview Create a method public static void spongeBobify(String inputPath, String outputPath, Mode mode) that will convert a file to Mocking Sponge Bob text in 3 different modes. EveryOther capitalize the first letter of the string capitalize every other letter (ignoring non-letter character like punctuation and spaces). non-letter characters don't count toward the every other count Example: mocking sponge bob! → MoCkInG sPoNgE bOb! Vowels capitalize every vowel (not including y) Random capitalize each letter with a probability of 35%....

  • Im try to create a java program that checks to see if a given boolean expression...

    Im try to create a java program that checks to see if a given boolean expression is a tautology or not my code so far is as follows: public static class TreeNode    {        char data;        TreeNode left;        TreeNode right;               TreeNode(char item)        {            data = item;            left = null;            right = null;        }    } public static...

  • Write a Java program which takes a string as a user input. Create 2 functions. The...

    Write a Java program which takes a string as a user input. Create 2 functions. The first function expects a string as argument and returns void. It converts all upper case characters to lower case and converts all lower case characters to upper case. It then prints out the converted string to a console. The second function also expects a string as argument and returns void. It will find first charactor that is repeated exactly 2 times in the string....

  • Create a Java program that uses the concepts below:   String myName = "Rick";     int length...

    Create a Java program that uses the concepts below:   String myName = "Rick";     int length = myName.length();     char firstChar = myName.charAt(0);     char secondChar = myName.charAt(1);     if (myName.equals("Jerry")) {       System.out.println ("Don't be a Jerry");   } Write a program that uses a METHOD to translate numbers (1-10) into their verbal counterparts. ex: 1 would be translated into "one" DO NOT use arrays or subStrings for this task!!! Sample output: Enter a String: 123 one two three

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT