• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Extract all the System.out.println("some tex"+ Sum) and the value of variable insed it

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
urgent help needed please,
please have a look the output of this code and the expected out put that i want.



OUTPUT
System.out.println("please enter the number");
System.out.println("sum is grater than 100"+ sum);
System.out.println("i is grater than 50"+ sum);
System.out.println("sum is less than 50"+ sum);

expected output is instead of sum i want print its value
System.out.println("please enter the number"45);
System.out.println("sum is grater than 100"45);
System.out.println("i is grater than 50"45);
System.out.println("sum is less than 50"45);
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The regular expression engine simply extracts text. You give it a pattern, and a source, and it will find the pattern in the source. And that's it. There is no automatic replace capability.

The regex engine does have replace capability, if you tell it what to look for and replace with. It is not a pattern though, so, you will have to code it to use it.

Henry
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

First question, how comfortable are you with regular expressions? My original assumption was that you are... but in reading it again, there were little in the post that warrant that.

... regardless, the Scanner class that you are using, and how you are using it (line by line), doesn't have direct replace capability. However, the line that is read in, is held in a string, and does have regex replace capability. Additionally, if you are uncomfortable with regex, the String class also has search and replace capability, that doesn't require knowledge of regexes. Take a look at the Documentation for the String class for more details.

Henry
 
Mohammad Ali Raisi
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i need the code that fixed my problem please and it is urgent the reference that you are giving need time to I learn those things
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mohammad Ali Raisi wrote:i need the code that fixed my problem please and it is urgent the reference that you are giving need time to I learn those things



Unfortunately, or more correctly, fortunately, the ranch is for learning. The policy is to help the poster understand the issue, and give hints in the right direction. Sorry, but even if a rancher decides to ignore the policy, the moderators on this site will have to delete the posted solution.

Henry
 
Mohammad Ali Raisi
Ranch Hand
Posts: 32
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please help me it is homework and i am new in programming
 
Space seems cool in the movies, but once you get out there, it is super boring. Now for a fascinating tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic